package view.campaign;

import javax.swing.JPanel;
import javax.swing.SpringLayout;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JComboBox;
import java.awt.Dimension;
import javax.swing.JSeparator;
import java.awt.Font;
import java.awt.event.ActionListener;

public class CampaignHome extends JPanel
{
	private JTable table;
	private JTextField tStartDate;
	private JTextField tEndDate;
	private JButton btnApplyFilter;
	private JComboBox comboCreatedBy;
	private JButton btnCl;
	private JButton btnCl1;
	
	public CampaignHome() 
	{
		SpringLayout springLayout = new SpringLayout();
		setLayout(springLayout);
		
		JLabel lblStartDate = new JLabel("Start Date");
		lblStartDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, lblStartDate, 30, SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.WEST, lblStartDate, 30, SpringLayout.WEST, this);
		add(lblStartDate);
		
		tStartDate = new JTextField();
		tStartDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, tStartDate, 6, SpringLayout.SOUTH, lblStartDate);
		springLayout.putConstraint(SpringLayout.WEST, tStartDate, 30, SpringLayout.WEST,this);
		add(tStartDate);
		tStartDate.setColumns(10);
		
		btnCl1=new JButton();
		btnCl1.setText("Cl");
		springLayout.putConstraint(SpringLayout.NORTH, btnCl1, 0, SpringLayout.NORTH,tStartDate);
		springLayout.putConstraint(SpringLayout.WEST,btnCl1 , 10, SpringLayout.EAST, tStartDate);
		springLayout.putConstraint(SpringLayout.SOUTH, btnCl1, 0, SpringLayout.SOUTH, tStartDate);
		add(btnCl1);
		btnCl1.setActionCommand("Cl");
		
		JLabel lblEndDate = new JLabel("End Date");
		lblEndDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, lblEndDate, 0, SpringLayout.NORTH,lblStartDate);
		springLayout.putConstraint(SpringLayout.WEST, lblEndDate, 30, SpringLayout.EAST,btnCl1);
		add(lblEndDate);
		
		tEndDate = new JTextField();
		tEndDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, tEndDate, 0, SpringLayout.NORTH,tStartDate);
		springLayout.putConstraint(SpringLayout.WEST, tEndDate, 0, SpringLayout.WEST, lblEndDate);
		add(tEndDate);
		tEndDate.setColumns(10);
		
		btnCl=new JButton();
		btnCl.setText("Cl");
		springLayout.putConstraint(SpringLayout.NORTH, btnCl, 0, SpringLayout.NORTH,tStartDate);
		springLayout.putConstraint(SpringLayout.WEST,btnCl , 10, SpringLayout.EAST, tEndDate);
		springLayout.putConstraint(SpringLayout.SOUTH, btnCl, 0, SpringLayout.SOUTH, tStartDate);
		add(btnCl);
		btnCl.setActionCommand("Cl");
		
		comboCreatedBy = new JComboBox();
		springLayout.putConstraint(SpringLayout.WEST, comboCreatedBy, 30, SpringLayout.EAST, btnCl);
		comboCreatedBy.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		comboCreatedBy.setPreferredSize(new Dimension(250, 23));
		springLayout.putConstraint(SpringLayout.NORTH, comboCreatedBy, 0, SpringLayout.NORTH,tEndDate);
		add(comboCreatedBy);
		
		btnApplyFilter = new JButton("Apply Filter");
		springLayout.putConstraint(SpringLayout.WEST, btnApplyFilter, 30, SpringLayout.EAST, comboCreatedBy);
		btnApplyFilter.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, btnApplyFilter, 0, SpringLayout.NORTH,tEndDate);
		add(btnApplyFilter);
		btnApplyFilter.setActionCommand("Apply Filter");
		
		JSeparator separator = new JSeparator();
		springLayout.putConstraint(SpringLayout.NORTH, separator, 30, SpringLayout.SOUTH, tStartDate);
		springLayout.putConstraint(SpringLayout.WEST, separator, 30, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.EAST, separator, -30, SpringLayout.EAST, this);
		add(separator);
		
		JScrollPane scrollPane = new JScrollPane();
		springLayout.putConstraint(SpringLayout.NORTH, scrollPane, 30, SpringLayout.NORTH,separator);
		springLayout.putConstraint(SpringLayout.WEST, scrollPane, 30, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.SOUTH, scrollPane, -30, SpringLayout.SOUTH, this);
		springLayout.putConstraint(SpringLayout.EAST, scrollPane, -30, SpringLayout.EAST, this);
		add(scrollPane);
		
		table = new JTable();
		table.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"CampaignName", "CreatedBy", "StartDate", "EndDate", "Description"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				false, false, false, false, false
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		scrollPane.setViewportView(table);
		
	}
	public JTable getTable() {
		return table;
	}
	public void setTable(JTable table) {
		this.table = table;
	}
	public JTextField gettStartDate() {
		return tStartDate;
	}
	public void settStartDate(JTextField tStartDate) {
		this.tStartDate = tStartDate;
	}
	public JTextField gettEndDate() {
		return tEndDate;
	}
	public void settEndDate(JTextField tEndDate) {
		this.tEndDate = tEndDate;
	}
	public JButton getBtnApplyFilter() {
		return btnApplyFilter;
	}
	public void setBtnApplyFilter(JButton btnApplyFilter) {
		this.btnApplyFilter = btnApplyFilter;
	}
	public JComboBox getComboCreatedBy() {
		return comboCreatedBy;
	}
	public void setComboCreatedBy(JComboBox comboCreatedBy) {
		this.comboCreatedBy = comboCreatedBy;
	}	
	
	
	public JButton getBtnCl() {
		return btnCl;
	}
	public void setBtnCl(JButton btnCl) {
		this.btnCl = btnCl;
	}
	public JButton getBtnCl1() {
		return btnCl1;
	}
	public void setBtnCl1(JButton btnCl1) {
		this.btnCl1 = btnCl1;
	}
	public void actionListener(ActionListener al)
	{
		btnApplyFilter.addActionListener(al);
		btnCl.addActionListener(al);
		btnCl1.addActionListener(al);
	}
}
